<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var initFn = (function(){
      var obj = {
        name: '张三',
        age: 28,
        car: [
          {
            name: 'benzs'    
          },
          {
            name:'mazda',
            color: 'red'
          }
        ],
        son: {
          name: '李四',
          age: 19
        }
      }


      var deep = {};
      
      function DeepCopy(){}

      DeepCopy.prototype.copy = function(target, origin){
        for(var key in origin){
          if (origin.hasOwnProperty(key) && origin[key] != null) {
            if(Array.isArray(origin[key])) {
              target[key] = [];
              this.copy(target[key], origin[key])
            } else if(typeof(origin[key]) === 'object') {
              target[key] = {}
              this.copy(target[key], origin[key])
            } else {
              target[key] = origin[key];
            }
          }
        }
      }

      new DeepCopy().copy(deep, obj);

      console.log(deep);
      
    });

    initFn();
  </script>
</body>
</html>